<ul id="error_message_box"></ul>
<?php
echo form_open('items/delete_category/',array('id'=>'category_form'));
?>
<fieldset id="item_basic_info">
<legend><?php echo $this->lang->line("categories_categories"); ?></legend>

<div id="table_holder">
<?php echo $categories_table; ?>
<br>
<a href="index.php/items/views_categories/-1/width:<?php echo $form_width ?>" class="thickbox none" title="<?php echo $this->lang->line('categories_new') ?>">
	<div class='submit_button' style='float: right;'><span><?php echo $this->lang->line('categories_new') ?></span></div>
</a>
<?php
echo form_submit(array(
	'name'=>'submit',
	'id'=>'submit',
	'value'=>$this->lang->line('common_delete'),
	'class'=>'submit_button float_right')
);
?>

</div>


</fieldset>
<?php

echo form_close();
?>
<script type='text/javascript'>

//validation and submit handling
$(document).ready(function()
{
	enable_cat_select_all();
    enable_checkboxes();
	$('#category_form').validate({
		submitHandler:function(form)
		{
			if(confirm("<?php echo $this->lang->line('categories_confirm_delete') ?>"))
			{
				//Get the selected ids and create hidden fields to send with ajax submit.
				var selected_category_ids=get_selected_values();
				for(k=0;k<selected_category_ids.length;k++)
				{
					$(form).append("<input type='hidden' name='category_ids[]' value='"+selected_category_ids[k]+"' />");
				}
				
				$(form).ajaxSubmit({
				success:function(response)
				{
					tb_remove();
					post_item_form_submit(response);
				},
				dataType:'json'
			
				});
			}
        
		},
		errorLabelContainer: "#error_message_box",
 		wrapper: "li",
		rules:
		{
   		},
		messages:
		{
						
		}
	});
});

function get_selected_values()
{
	var selected_values = new Array();
	$("#cat_sortable_table tbody :checkbox:checked").each(function()
	{
		selected_values.push($(this).val());
	});
	return selected_values;
}

function enable_cat_select_all()
{
	//Keep track of enable_select_all has been called
	if(!enable_select_all.enabled)
		enable_select_all.enabled=true;

	$('#cat_select_all').click(function()
	{
		if($(this).attr('checked'))
		{	
			$("#cat_sortable_table tbody :checkbox").each(function()
			{
				$(this).attr('checked',true);
				$(this).parent().parent().find("td").addClass('selected').css("backgroundColor","");

			});
		}
		else
		{
			$("#cat_sortable_table tbody :checkbox").each(function()
			{
				$(this).attr('checked',false);
				$(this).parent().parent().find("td").removeClass();				
			});    	
		}
	 });	
}
</script>

